package com.car.loan.framework.aspectj.impl;

import com.car.loan.common.enums.LoanStatusEnum;
import com.car.loan.common.utils.StringUtils;
import com.car.loan.framework.aspectj.DataStatusSqlService;
import com.car.loan.project.xr.util.bo.business.LoanBaseInfo;
import com.car.loan.project.xr.util.enums.CarInfoStatus;
import com.car.loan.project.xr.util.enums.ContractInfoStatus;
import com.car.loan.project.xr.util.enums.FileAuditStatus;
import org.springframework.stereotype.Service;

/**
 * @author huangding
 * @date 2020/2/18 19:54
 */
@Service
public class ContractInfoStatusSqlServiceImpl implements DataStatusSqlService {

    @Override
    public LoanStatusEnum getLoanStatusEnum() {
        return LoanStatusEnum.CONTRACT_INFO_STATUS;
    }

    @Override
    public String getSql(String statusAlias, Integer status) {
        String sql =
            "{}.file_audit_status = " + FileAuditStatus.INIT.status + " and {}.car_info_status = "
                + CarInfoStatus.SUBMIT.status;
        if (status != null) {
            sql += " and {}.contract_info_status =  " + status;
        }
        return sql.replace("{}", statusAlias);
    }

    @Override
    public LoanBaseInfo getStatusRemark(LoanBaseInfo loanBaseInfo) {
        Long contractInfoStatus = loanBaseInfo.getContractInfoStatus();
        String statusRemark = StringUtils.EMPTY;
        if (ContractInfoStatus.INIT.status == contractInfoStatus) {
            statusRemark = "未提交";
        } else if (ContractInfoStatus.SUBMIT.status == contractInfoStatus) {
            statusRemark = "已提交";
        }
        loanBaseInfo.setStatusRemark(statusRemark);
        return loanBaseInfo;
    }

    @Override
    public String getSortSql(String statusAlias) {
        return " order by {}.car_info_time desc".replace("{}", statusAlias);
    }
}
